package org.interview.ms.simplearray;


public class DublicatElementCleaner {

	public static void main(String[] args) {

		int[] test = {1,2,1,1,3,1,1,1,1,1,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
		int[] result = getUniqeList(test);
		
		System.out.println("_________________");
		System.out.println(result.length);
		for (int i = 0; i < result.length; i++) {
			System.out.println(result[i]);
		}
		
			
		
	}

	private static int[] getUniqeList(int[] processingArray) {
		
		if (processingArray == null || processingArray.length == 0){
		  return null;	
		}
		
		int[] tempArray = new int[processingArray.length] ;
		int uniqueElementQuantity = 0;
		//System.out.println(processingArray.length);
		
		for (int index = 0; index < processingArray.length; index++) {
			if (!isArrayContainsElement(tempArray, processingArray[index])){
				tempArray[uniqueElementQuantity] = processingArray[index];
				uniqueElementQuantity++;
			}
		}
		
		int[] uniqueArray = new int[uniqueElementQuantity];
		
		for (int i = 0; i < uniqueElementQuantity; i++) {
			uniqueArray[i] = tempArray[i]; 
		}
		
		return uniqueArray;
	}

	

	
	private static boolean isArrayContainsElement(int[] array, int element) {

		if (array == null || array.length == 0) {
			return true;
		}

		for (int i = 0; i < array.length; i++) {
			System.out.println("comparing " + array[i]);
			if (element == array[i]) {
				return true;
				
			}
			
			
		}

		return false;
		
	}

}
